import api from '../utils/api';

// 服务预约类型定义
export interface ServiceAppointment {
  id: number;
  elderlyId: number;
  elderlyName: string;
  familyId: number;
  familyName: string;
  serviceType: string; // 服务类型
  appointmentTime: string; // 预约时间
  description: string; // 服务描述
  status: number; // 1-待确认，2-已确认，3-已完成，4-已取消
  remark: string; // 备注
  createTime: string;
  updateTime: string;
}

// 服务预约服务类
class ServiceAppointmentService {
  // 创建服务预约
  async createAppointment(params: {
    elderlyId: number;
    familyId: number;
    serviceType: string;
    appointmentTime: string;
    description: string;
  }): Promise<ServiceAppointment> {
    return await api.post('/service/create', params);
  }

  // 确认服务预约
  async confirmAppointment(id: number, remark?: string): Promise<ServiceAppointment> {
    return await api.put(`/service/confirm/${id}`, { remark });
  }

  // 完成服务预约
  async completeAppointment(id: number, remark?: string): Promise<ServiceAppointment> {
    return await api.put(`/service/complete/${id}`, { remark });
  }

  // 取消服务预约
  async cancelAppointment(id: number, remark?: string): Promise<ServiceAppointment> {
    return await api.put(`/service/cancel/${id}`, { remark });
  }

  // 获取老人的服务预约列表
  async getElderlyAppointments(elderlyId: number): Promise<ServiceAppointment[]> {
    return await api.get(`/service/elderly/${elderlyId}`);
  }

  // 获取家属的服务预约列表
  async getFamilyAppointments(familyId: number): Promise<ServiceAppointment[]> {
    return await api.get(`/service/family/${familyId}`);
  }

  // 获取待处理的服务预约
  async getPendingAppointments(): Promise<ServiceAppointment[]> {
    return await api.get('/service/pending');
  }

  // 获取服务预约详情
  async getAppointmentDetail(id: number): Promise<ServiceAppointment> {
    return await api.get(`/service/detail/${id}`);
  }

  // 获取所有服务预约（分页）
  async getAllAppointments(page: number = 1, size: number = 10): Promise<any> {
    return await api.get('/service/list', {
      page,
      size
    });
  }
}

export default new ServiceAppointmentService();